package org.ghost.parallel.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierTest implements Runnable {
    private final static Logger logger = LoggerFactory.getLogger(CyclicBarrierTest.class);
    private static CyclicBarrier cyclicBarrier = new CyclicBarrier(3, new Runnable() {
        @Override
        public void run() {
            logger.info("*****达到条件,开始处理数据*****");
        }
    });

    @Override
    public void run() {
        try {
            cyclicBarrier.await();
            logger.info("*****数据处理完毕*****");
        } catch (InterruptedException | BrokenBarrierException e) {
            logger.error("*****CyclicBarrierTest.run出现异常,{},{}", e.getMessage(), e);
        }

    }
}
